package sxkyxt.kjyxgs.cn.ishop_gather_uploading_android;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;



public class TitleActivity extends BaseActivity implements OnClickListener {

    public static RelativeLayout mLayoutTitleBar;
    public static TextView mTitleTextView;
    private Button mBackwardbButton;
    private Button mForwardButton;
    private FrameLayout mContentLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setupViews();
    }

    private void setupViews() {
        super.setContentView(R.layout.activity_title);
        mTitleTextView = (TextView) findViewById(R.id.text_title);
//        mTitleTextView.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                onTextLisner();
//            }
//        });
        mContentLayout = (FrameLayout) findViewById(R.id.layout_content);
        mBackwardbButton = (Button) findViewById(R.id.button_backward);
        Drawable drawable = getResources().getDrawable(R.mipmap.back_arrow);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        setCompoundDrawablesButtonBack(drawable);
        mForwardButton = (Button) findViewById(R.id.button_forward);
        mLayoutTitleBar = (RelativeLayout) findViewById(R.id.layout_titlebar);
    }


    protected void showBackwardView(int backwardResid, boolean show) {
        if (mBackwardbButton != null) {
            if (show) {
                mBackwardbButton.setText(backwardResid);
                mBackwardbButton
                        .setBackgroundResource(R.drawable.back_button_selector);
                mBackwardbButton.setVisibility(View.VISIBLE);
            } else {
                mBackwardbButton.setVisibility(View.INVISIBLE);
            }
        } // else ignored
    }


    protected void showForwardView(int forwardResId, boolean show) {
        if (mForwardButton != null) {
            if (show) {
                mForwardButton.setVisibility(View.VISIBLE);
                mForwardButton
                        .setBackgroundResource(R.drawable.back_button_selector);
                mForwardButton.setText(forwardResId);
            } else {
                mForwardButton.setVisibility(View.INVISIBLE);
            }
        } // else ignored
    }


    protected void onBackward(View backwardView) {
        // Toast.makeText(this, "退出程序", Toast.LENGTH_LONG).show();
        ActivityStack.getInstance().removeActivity(this);
        finish();
    }


    protected void onForward(View forwardView) {
        // TODO 按钮监听
    }

   protected  void setCompoundDrawablesButtonBack(){
       mBackwardbButton.setCompoundDrawables(null,null,null,null);
   }

    protected   void  setCompoundDrawablesButtonBack(Drawable drawable){
//        Drawable drawable = getResources().getDrawable(R.drawable.ic_right);
//        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        mBackwardbButton.setCompoundDrawables(drawable,null,null,null);

    }


    @Override
    public void setTitle(int titleId) {
        mTitleTextView.setText(titleId);
    }

    @Override
    public void setTitle(CharSequence title) {
        mTitleTextView.setText(title);
    }


    @Override
    public void setTitleColor(int textColor) {
        mTitleTextView.setTextColor(textColor);
    }

    @Override
    public void setContentView(int layoutResID) {
        mContentLayout.removeAllViews();
        View.inflate(this, layoutResID, mContentLayout);
        onContentChanged();
    }

    @Override
    public void setContentView(View view) {
        mContentLayout.removeAllViews();
        mContentLayout.addView(view);
        onContentChanged();
    }

    /*
     * (non-Javadoc)
     *
     * @see android.app.Activity#setContentView(android.view.View,
     * android.view.ViewGroup.LayoutParams)
     */
    @Override
    public void setContentView(View view, LayoutParams params) {
        mContentLayout.removeAllViews();
        mContentLayout.addView(view, params);
        onContentChanged();
    }

    /*
     * (non-Javadoc)
     *
     * @see android.view.View.OnClickListener#onClick(android.view.View)
     * 鎸夐挳鐐瑰嚮璋冪敤鐨勬柟娉�
     */
    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.button_backward:
                onBackward(v);
                break;

            case R.id.button_forward:
                onForward(v);
                break;

            default:
                break;
        }
    }

    public static void setFragmentTitle(String Title) {
        mTitleTextView.setText(Title);
    }


}
